home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Unix / CNews / Source / conf / dostatfs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-28  |  1.3 KB  |  61 lines

  1. /*
  2.  * dostatfs - the heart of spacefor.statfs
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <sys/types.h>
  8. #include <sys/mount.h>
  9. #ifndef MNAMELEN
  10. /* this does not seem to be a 4.4BSD, try for SunOS */
  11. #include <sys/vfs.h>
  12. #define    f_fsize    f_bsize        /* idiotic incompatible naming in 4.4 */
  13. #endif
  14.  
  15. extern int debug;
  16.  
  17. extern void error(), exit();
  18.  
  19. /*
  20.  - process - do the work
  21.  */
  22. long
  23. process(filesize, fileonfs, wantspace, wantinodes, bperi)
  24. long filesize;
  25. char *fileonfs;
  26. long wantspace;
  27. long wantinodes;
  28. long bperi;
  29. {
  30.     struct statfs info;
  31.     register long n;
  32. #    define    LOTS    10000
  33.     register long iperfile = filesize/bperi + 1;
  34.  
  35.     if (statfs(fileonfs, &info) < 0)
  36.         error("cannot do statfs(%s)", fileonfs);
  37.     if (debug)
  38.         fprintf(stderr, "bsize %ld, avail %ld, inodes %ld\n",
  39.                 info.f_fsize, info.f_bavail, info.f_ffree);
  40.  
  41.     n = LOTS;
  42.     if (info.f_bavail <= wantspace)
  43.         n = 0;
  44.     else if (info.f_fsize > 0 && filesize > 0)
  45.         n = (info.f_bavail - wantspace) / (filesize/info.f_fsize + 1);
  46.  
  47.     if (info.f_ffree < 0)        /* information unavailable */
  48.         ;            /* bypass check, and pray */
  49.     else if (info.f_ffree <= wantinodes)
  50.         n = 0;
  51.     else if ((info.f_ffree - wantinodes) / iperfile < n)
  52.         n = (info.f_ffree - wantinodes) / iperfile;
  53.  
  54.     if (n < 0)
  55.         n = 0;
  56.     else if (n > LOTS)
  57.         n = LOTS;    /* to avert 16-bit trouble elsewhere */
  58.  
  59.     return(n);
  60. }
  61.